package com.fivezerotwo.springbootserver.common.ReturnModel;

import java.util.List;

/**
 * 常用返回类型
 * Created by qiqi on 2018/7/25 22:42
 */
public class ReturnModel {
    private static final String SUCCESS = "SUCCESS";

    public static Result successRequest() {
        return new Result()
                .setCode(ReturnCode.SUCCESS)
                .setMessage(SUCCESS);
    }

    public static Result successRequest(Object data) {
        return new Result()
                .setCode(ReturnCode.SUCCESS)
                .setData(data)
                .setMessage(SUCCESS);
    }

    public static Result failRequest(String message) {
        return new Result()
                .setCode(ReturnCode.FAIL)
                .setMessage(message);
    }

    public static Result serverFailRequest(String message) {
        return new Result()
                .setCode(ReturnCode.SERVICE_FAIL)
                .setMessage(message);
    }
    public static Result NotFountRequest(String message) {
        return new Result()
                .setCode(ReturnCode.NOT_FOUND)
                .setMessage(message);
    }
    public static Result serverErroRequest(String message) {
        return new Result()
                .setCode(ReturnCode.INTERNAL_SERVER_ERROR)
                .setMessage(message);
    }

    public static <T> Result successPageRequest(List<T> data) {
        return new Result()
                .setCode(ReturnCode.SUCCESS)
                .setData(new ResultPage<T>().setData(data))
                .setMessage(SUCCESS);
    }

    public static <T> Result successPageRequest(int total, List<T> data) {
        return new Result()
                .setCode(ReturnCode.SUCCESS)
                .setData(new ResultPage<T>().setTotal(total).setData(data))
                .setMessage(SUCCESS);
    }

}
